package com.glory.eapequipmentmonitor.activity;

import android.os.Handler;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.glory.eapequipmentmonitor.R;
import com.glory.eapequipmentmonitor.base.Constant;
import com.pda.platform.ui.ui_pdaplatform.base.FreeUI_BaseActivity;
import com.pda.platform.ui.ui_pdaplatform.entity.FreeUI_AddViewEntity;
import com.pda.platform.ui.ui_pdaplatform.view.FreeUI_ClearEditText;

import butterknife.BindView;
import butterknife.OnClick;

public class AbortActivity extends FreeUI_BaseActivity {


    @BindView(R.id.llMain)
    LinearLayout llMain;
    @BindView(R.id.tvUser)
    TextView tvUser;
    @BindView(R.id.etLotId)
    FreeUI_ClearEditText etLotId;
    @BindView(R.id.etRemark)
    FreeUI_ClearEditText etRemark;
    @BindView(R.id.tvLotTitle)
    TextView tvLotTitle;

    private String actionType = "BYLOT";

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_abort;
    }

    @Override
    protected void initView() {
        tvUser.setText(Constant.CURRENT_USER);
        freeUI_titleView.setTitle("取消作业");
        freeUI_titleView.setRightListener("提交", new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String lotId = etLotId.getText().toString().trim();
                if (lotId.length() == 0) {
                    showToast("请扫描生产批号", false);
                    return;
                }
                String remark = etRemark.getText().toString().trim();
                if (remark.length() == 0) {
                    showToast("请输入取消说明", false);
                    return;
                }
                showToast("取消作业成功", true);
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        AbortActivity.this.finish();
                    }
                }, 2000);
            }
        });
    }

    @Override
    protected void initData() {
        etLotId.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (start == 0 && before == 0 && count > 1) {
                    etRemark.requestFocus();
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }

    @Override
    protected FreeUI_AddViewEntity getBaseEntity() {
        return new FreeUI_AddViewEntity("header", llMain);
    }

    @OnClick({R.id.rbLot, R.id.rbWork})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rbLot:
                actionType = "BYLOT";
                tvLotTitle.setText("生产批号：");
                etLotId.setHint("请扫描生产批号");
                etLotId.setText("");
                break;
            case R.id.rbWork:
                actionType = "BYWO";
                tvLotTitle.setText("工单号　：");
                etLotId.setHint("请扫描工单号");
                etLotId.setText("");
                break;
        }
    }

}
